package com.socialuni.center.web.controller;

import com.socialuni.sdk.api.model.QO.talk.*;
import com.socialuni.sdk.api.model.RO.talk.SocialTalkRO;
import com.socialuni.sdk.api.model.ResultRO;
import com.socialuni.center.web.serive.api.CenterTalkService;
import com.socialuni.sdk.api.TalkAPI;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;

@RestController
public class CenterTalkController implements TalkAPI {
    @Resource
    CenterTalkService centerTalkService;

    @Override
    public ResultRO<List<SocialTalkRO>> queryTalks() {
        return new ResultRO<>(centerTalkService.queryTalks(new SocialHomeTalkQueryQO()));
    }

    //查询官方置顶的talks
    //没有商户号的情况下，appGender也可以人工设置不为空
    @Override
    public ResultRO<List<SocialTalkRO>> queryTalks(SocialHomeTalkQueryQO queryVO) {
        return new ResultRO<>(centerTalkService.queryTalks(queryVO));
    }

    @Override
    public ResultRO<List<SocialTalkRO>> queryUserTalks(SocialUserTalkQueryQO queryVO) {
        return new ResultRO<>(centerTalkService.queryUserTalks(queryVO));
    }

    @Override
    public ResultRO<Void> addTalk(SocialTalkAddQO talkVO) {
        centerTalkService.addTalk(talkVO);
        return new ResultRO<>();
    }

    @Override
    public ResultRO<Void> deleteTalk(SocialTalkDeleteQO talkVO) {
        centerTalkService.deleteTalk(talkVO);
        return new ResultRO<>();
    }

    @Override
    public ResultRO<SocialTalkRO> queryTalkInfo(TalkIdQO talkIdQO) {
        return centerTalkService.queryTalkDetail(talkIdQO);
    }

    @PostMapping("queryTalkDetail")
    ResultRO<SocialTalkRO> queryTalkDetail(@Valid @NotBlank String talkId) {
        TalkIdQO talkIdQO = new TalkIdQO(talkId);
        return centerTalkService.queryTalkDetail(talkIdQO);
    }
}